package net.andrea.girardello.view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import net.andrea.girardello.Midlet;
import net.andrea.girardello.controller.ImageLoader;

/**
 *
 * @author agirardello
 */
public class ConfirmView extends Form implements CommandListener {

    private Midlet main;

    private StringItem info;
    private StringItem connectionInfo;
    private ImageItem imageItem;
    
    private Command continueCommand;
    private Command exitCommand;

    public ConfirmView(String title, Midlet main) {
        super(title);
        this.main = main;
        setupItems();
    }
    
    private void setupItems() {
        
        imageItem = new ImageItem(null, ImageLoader.getImage("question.png"), ImageItem.LAYOUT_NEWLINE_BEFORE, "No image");
        imageItem.setLayout(ImageItem.LAYOUT_CENTER);
        this.append(imageItem);
        
        info = new StringItem("", "Would you check the webcam placed in the mensa?");
        info.setLayout(StringItem.LAYOUT_NEWLINE_AFTER);
        info.setLayout(Item.LAYOUT_LEFT);
        this.append(info);
        
        connectionInfo = new StringItem("", "This requires internet connection and may cost for you.");
        connectionInfo.setLayout(Item.LAYOUT_LEFT);
        connectionInfo.setLayout(StringItem.LAYOUT_NEWLINE_AFTER);
        this.append(connectionInfo);
        
        exitCommand = new Command("Exit", Command.EXIT, 0);
        this.addCommand(exitCommand);
        this.setCommandListener(this);
        
        continueCommand = new Command("Continue", Command.OK, 0);
        this.addCommand(continueCommand);
        this.setCommandListener(this);
    }

    public void commandAction(Command command, Displayable arg1) {
        if (command == exitCommand){
            main.destroyApp(true);
        } else if (command == continueCommand){
            main.showDisplay( new CamView("MensaCam", main) );
        }
    }
}
